package com.ccp.dev.system.service;


import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.system.dao.FileManagementLogDao;
import com.ccp.dev.system.model.FileManagementLog;
import com.ccp.dev.system.model.SysUser;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;

/**
 * ClassDescribe:文件管理service类
 * Author :zhaowanjing
 * Date: 2018-05-18
 * Since:1
 */
@Service
public class FileManagementLogService extends BaseService<FileManagementLog> {
    @Resource
    private FileManagementLogDao fileManagementLogDao;

    /**
     * 添加文件操作日志
     * @param fileId 文件/文件夹ID
     * @param fileName 文件/文件夹名称
     * @param fileStorage 文件存储路径
     * @param operatorType 操作类型 1上传 2下载 3删除 4重命名
     * @throws Exception
     */
    public void addLog(String fileId,String fileName,String fileStorage,Integer operatorType) throws Exception {
        // 获取当前用户
        SysUser sysUser = (SysUser) ContextUtil.getCurrentUser();
        //设置其他默认属性
        String logId = UUIDUtils.getUUIDFor32();
        FileManagementLog fileManagementLog = new FileManagementLog();
        fileManagementLog.setId(logId);
        fileManagementLog.setOperatorDate(new Date());
        fileManagementLog.setOperatorId(sysUser.getUserId());
        fileManagementLog.setOperatorName(sysUser.getUsername());
        //设置文件属性
        fileManagementLog.setFileId(fileId);
        fileManagementLog.setFileName(fileName);
        fileManagementLog.setFileStorage(fileStorage);
        fileManagementLog.setOperatorType(operatorType);
        fileManagementLogDao.add(fileManagementLog);
    }
}
